/**
 * Copyright 2008 Martin 'Windgazer' Reurings
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.windgazer.maven.plugins.jsdoc;

import java.io.File;
import java.util.Locale;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;

/** 
 * Run JSDoc on the current webapp. This mojo contains a version of
 * JSDoc and wraps around it to be able to run it using Maven 2.<br />
 * Developers have access to all the 'options' that JSDoc has and
 * they can be overridden using mavens' plugin configuration.<br />
 * <br />
 * See the <code>JSDocGenerator</code> for configuration options.
 *
 * @see JSDocGenerator
 * @author mreuring
 * @goal jsdoc
 */
public class JSDocMojo extends AbstractMojo {
	
	/**
     * The temporary directory where JSDoc toolkit is stored while running.
     * This is not a JSDoc property, and won't be found in the JSDoc documentation.
     *
     * @parameter expression="${project.build.directory}/toolkit"
     */
	private File tempDir;
	
	/**
     * Template used to format the output. The opions are 'htm', 'sunny' or 'xml'.
     * This property represents: -t=<PATH> or --template=<PATH>
     *
     * @parameter expression="htm"
     */
	private String template;
	
	/**
     * The target directory where you want the generated doc to end up. This
     * property represents: -d=&lt;PATH> or --directory=&lt;PATH>.
     *
     * @parameter expression="${project.build.directory}/jsdoc"
     */
	private File directory;
	
	/**
	 * The level of recursion. Default is 1.
	 * 
	 * @parameter expression="1"
	 */
	private int recurse;
	
	/**
	 * The extension for the javascript files, default is 'js'.
	 * 
	 * @parameter expression="js"
	 */
	private String extension;
	
	/**
	 * Include all functions in the JSDoc, including undocumented ones.
	 * 
	 * @parameter expression="true"
	 */
	private boolean allFunctions;

	/**
	 * Include all functions in the JSDoc, including undocumented and underscored ones.
	 * 
	 * @parameter expression="false;
	 */
	private boolean AllFunctions;
	
	/**
	 * Include symbols tagged as private.
	 * 
	 * @parameter expression="false"
	 */
	private boolean privateOption;

	
	/**
	 * The directory where we may find the source-files we're making jsdocs for.
	 * This property represents: &lt;SRC_DIR>
	 * 
	 * @parameter expression="${basedir}/src/main/webapp"
	 */
	private File srcDir; //TODO: Find the expression for the current project-dir!

	/**
	 * Execute the mojo, this is what mvn calls to start this mojo.
	 */
	public void execute() throws MojoExecutionException {
		JSDocGenerator gen = new JSDocGenerator(tempDir, directory, srcDir, template, extension, recurse, allFunctions, AllFunctions, privateOption, getLog());
		Locale locale = Locale.getDefault();
		try {
			gen.generateReport(locale);
		} catch (JSDocException e) {
			throw new MojoExecutionException(e.getLocalizedMessage());
		}
	}

}
